package com.concurrent.threads.foo;

/**
 * @ClassName Foo1
 * @Description TODO
 * @Author li
 * Date 2021/8/23 0:04
 * Copyright
 **/
class Foo1 {
    private  int anInt  = 1;
    public Foo1() {

    }

    public void first(Runnable printFirst) throws InterruptedException {
        isStart(1);
        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        isStart(2);
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
    }

    public void third(Runnable printThird) throws InterruptedException {
        isStart(3);
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
    public  void isStart(int anInt){
        while (anInt != this.anInt){

        }
        synchronized (this){
            this.anInt++;
        }
    }
}